package com.wxzz.elearing.comment.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.comment.service.ISkillCenterCategoryService;
import com.wxzz.elearning.common.exception.ServiceException;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 技能沉淀/中心分类 前端控制器(wx)
 * </p>
 *
 * @author 
 * @since 2021-05-17
 */
@RestController
@RequestMapping("/wx-skill-center-category")
@Api(tags = "技能分类接口(小程序)")
public class WxSkillCenterCategoryController {

    @Autowired
    private ISkillCenterCategoryService skillCenterCategoryService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "展示技能分类(小程序)", notes = "展示技能分类(小程序)，默认type为1返回'全部' 0不返回", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listAllCategory/{type}", method = RequestMethod.POST)
    public ReturnVO listAllCategory(@RequestHeader String token, @PathVariable(value = "type", required = false) Integer type) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        if (jsonObject==null){
            throw new ServiceException("请先登录");
        }
        Long enterpriseId = jsonObject.getLong("enterpriseId");
        if (type==null) type = 1;
        return skillCenterCategoryService.listAllCategory(0L, enterpriseId, type);
    }


}
